package com.custom;
import android.app.Activity; import android.app.ActionBar.LayoutParams; import android.os.Bundle; import android.widget.Button; import android.widget.LinearLayout;
public class CustomEx1 extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //리니어 레이아웃 선언 LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); //기타 속성은 레이아웃 파라미터 객체에 지정 LayoutParams params1 = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); //레이아웃 파라미터를 리니어 레이아웃에 적용 layout.setLayoutParams(params1); //버튼을 선언 Button btn = new Button(this); btn.setText("버튼"); //기타 속성은 레이아웃 파라미터 객체에 지정 LayoutParams params2 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); //레이아웃 파라미터를 버튼에 적용 btn.setLayoutParams(params2); //우리가 정의한 커스텀 버튼을 정의 MyButton my_btn = new MyButton(this); my_btn.setLayoutParams(params2); my_btn.setText("커스텀 버튼");
//리니어에 버튼을 붙인다. layout.addView(btn); layout.addView(my_btn); setContentView(layout); } }
|